package com.sergio.gestion.entities;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.servlet.http.HttpSession;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository(value = "socioDao")
public class SocioDaoImpl implements SocioDao {
	
	private EntityManager em = null;
	
	/*
	 * Sets the eity manager.
	 */
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}

	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")
	public List<Socio> getAll(Integer firstResult,Integer maxResult) {
		Query query=em.createQuery("select p from Socio p order by p.id");
		query.setFirstResult(firstResult);
		query.setMaxResults(maxResult);
		return query.getResultList();
	}

	@Transactional(readOnly = false)
	public void saveProduct(Socio socio) {
		em.merge(socio);
	}

	public Integer countAll() {
		Query query=em.createQuery("select p from Socio p order by p.id");
		List<Socio> socios=query.getResultList();
		return socios.size();
		
	}

}
